library(tidyverse)
library('migest')

firstword = c(
  'Sub-Saharan',
  'Northern',
  'Europe',
  'Eastern Europe &',
  'Western',
  'Southern',
  'Eastern',
  'South-eastern',
  'Oceania',
  'Latin America &',
  'Northern'
)

secondword = c(
  'Africa',
  'Africa',
  '',
  'Central Asia',
  'Asia',
  'Asia',
  'Asia',
  'Asia',
  '',
  'the Caribbean',
  'America'
)

names(firstword) = c(
  'Sub-Saharan Africa',
  'Northern Africa',
  'Europe',
  'Eastern Europe and Central Asia',
  'Western Asia',
  'Southern Asia',
  'Eastern Asia',
  'South-eastern Asia',
  'Oceania',
  'Latin America and the Caribbean',
  'Northern America'
)

names(secondword) = c(
  'Sub-Saharan Africa',
  'Northern Africa',
  'Europe',
  'Eastern Europe and Central Asia',
  'Western Asia',
  'Southern Asia',
  'Eastern Asia',
  'South-eastern Asia',
  'Oceania',
  'Latin America and the Caribbean',
  'Northern America'
)

orders = c(
  'Sub-Saharan Africa',
  'Northern Africa',
  'Europe',
  'Eastern Europe and Central Asia',
  'Western Asia',
  'Southern Asia',
  'Eastern Asia',
  'South-eastern Asia',
  'Oceania',
  'Latin America and the Caribbean',
  'Northern America'
)

f = read_csv('migration_flow_subcontinent_map_2022.csv')
f$num_migrants = f$num_migrants / 1000000
pdf(file = paste0('figures/fig2a.pdf'))
mig_chord(x = f,
          lab_bend1=firstword,
          lab_bend2=secondword,
          order = orders,
          grid.col = colorRampPalette(migest::umbrella)(length(orders))
)
dev.off()
